function onload()
{
		for(i=0;i<{{max_id}};i++)
		{
				curr_item[i] = ""; 
		}
		{% for rf in report_detail %}
			{% if rf['item_flag'] == 1 %}  
				var{{rf['id']}}="{{rf['params']}}";
				curr_item[{{rf['id']}}-1]="{{rf['params']}}";
			{% endif %}
		{% endfor%}
}

function edit()
{
		document.getElementById("edit").style.display="none";
		document.getElementById("create_report").style.display="none";
		document.getElementById("add").style.display="block";
		document.getElementById("cancel").style.display="block";
		document.getElementById("save").style.display="block";
		//document.getElementById("save").disable();
		document.getElementById("save").disabled=true;
		{% for rf in report_detail %}
				{% if rf['item_flag'] == 1 %}  
						//document.getElementById("cr_{{rf['id']}}").enable();			
						document.getElementById("cr_{{rf['id']}}").disabled=false;
				{% endif %}
		{% endfor%}
}

function cancel()
{
		document.getElementById("edit").style.display="block";
		document.getElementById("create_report").style.display="block";
		document.getElementById("add").style.display="none";
		document.getElementById("cancel").style.display="none";
		document.getElementById("save").style.display="none";
		{% for rf in report_detail %}
				{% if rf['item_flag'] == 1 %}  
						document.getElementById("cr_{{rf['id']}}").value=var{{rf['id']}};
						//document.getElementById("cr_{{rf['id']}}").disable();
						document.getElementById("cr_{{rf['id']}}").disabled=true;
				{% endif %}
		{% endfor%}
		changed_items="";
}

function change_button_status(obj)
{       
		if(obj.value.strip() != curr_item[obj.id-1])
		{
				obj.value = obj.value.strip();
				//document.getElementById("save").enable();
				document.getElementById("save").disabled=false;
				if(changed_items.indexOf(obj.name) == -1)
				{
						changed_items += obj.name+";";
				}
		}
}
function add_item()
{
		form=document.getElementById("form1");
		form.action="create_report.py/add_item_page?report_id={{report_info['id']}}";
		form.submit();
}

function save()
{		
		document.getElementById("changed_items").value = changed_items;
		form = document.getElementById("form1");
		form.action="create_report.py/save_change?report_id={{report_info['id']}}";
		form.submit();
}

function create_report()
{
		form=document.getElementById("form_date");
		if(form==null){
				form=document.getElementById("form1");				
		}		
		form.action="create_report.py/report?report_id={{report_info['id']}}";
		form.submit();
		//document.getElementById("form_date").submit();
}
